<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改课程考试题')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-exam-edit" th:object="${bizCourseExam}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">所属课程内容：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="courseDetailId" type="hidden" th:value="*{courseDetailId}"/>
                        <input class="form-control" type="text" onclick="selectManageTree()" id="treeName"
                               readonly="true" th:value="*{courseDetailTitle}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">试题标题：</label>
                <div class="col-sm-8">
                    <input name="examTitle" th:field="*{examTitle}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">显示顺序：</label>
                <div class="col-sm-8">
                    <input name="orderNum" th:field="*{orderNum}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否启用：</label>
                <div class="col-sm-8">
                    <select  class="form-control m-b"  name="activeStatus" th:field="*{activeStatus}">
                        <option value="1">启用</option>
                        <option value="0">不启用</option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "biz/exam";
        $("#form-exam-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-exam-edit').serialize());
            }
        }

        function selectManageTree() {
            var options = {
                title: '课程选择',
                width: "380",
                url: prefix + "/selectManageTree/" + $("#treeId").val(),
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero) {
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if (checkL4(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(+body.find('#treeId').val()+100000);
                $("#treeName").val(body.find('#treeName').val());
                console.log('courseDetailId = ' + $("#treeId").val())
                layer.close(index);
            }
        }

        function checkL4(_tree) {
            var nodes = _tree.getSelectedNodes();
            if (nodes.length == 0) {
                $.modal.msgError("请选择节点后提交");
                return false;
            }
            for (var i = 0; i < nodes.length; i++) {
                if (nodes[i].level != 3) {
                    $.modal.msgError("数据不正确，请选择第四级菜单");
                    return false;
                }

            }
            return true;
        }
    </script>
</body>
</html>